<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改生产订单')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-order-edit" th:object="${processOrder}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">订单批号：</label>
                    <div class="col-sm-8">
                        <input name="orderCode" th:field="*{orderCode}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">客户名称：</label>
                    <div class="col-sm-8">
                        <input name="clientName" th:field="*{clientName}" class="form-control" type="text" onclick="selectClient()" id="clientName" readonly="readonly" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">客户电话：</label>
                    <div class="col-sm-8">
                        <input name="clientPhone" th:field="*{clientPhone}" class="form-control" type="text" readonly="readonly" id="clientPhone"  required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">产品ID：</label>
                    <div class="col-sm-8">
                        <input name="productId" th:field="*{productId}" class="form-control" type="text" readonly="readonly" id="productId"  required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">产品名称：</label>
                    <div class="col-sm-8">
                        <input name="productName" th:field="*{productName}" class="form-control" type="text" onclick="selectProduct()" readonly="readonly" id="productName" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">产品规格/型号：</label>
                    <div class="col-sm-8">
                        <input name="model" th:field="*{model}" class="form-control" type="text" readonly="readonly" id="productModel" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">数量：</label>
                    <div class="col-sm-8">
                        <input name="num" th:field="*{num}" class="form-control" type="text" id="num" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">单位：</label>
                    <div class="col-sm-8">
                        <select name="productUnitname" class="form-control"  required>
                            <option th:each="name : ${uniteNames}" th:text="${name}" th:value="${name}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">单价：</label>
                    <div class="col-sm-8">
                        <input name="signalPrice" th:field="*{signalPrice}" class="form-control" type="text" id="signal_price" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">金额：</label>
                    <div class="col-sm-8">
                        <input name="totalPrice" th:field="*{totalPrice}" class="form-control" type="text" readonly="readonly" onclick="computedMoney()" id="totalPrice"  required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">是否付款：</label>
                    <div class="col-sm-8">
                        <select name="pay" class="form-control" th:with="type=${@dict.getType('sys_pay_status')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{pay}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">需求日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="deadtime" th:value="${#dates.format(processOrder.deadtime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">箱长度：</label>
                    <div class="col-sm-8">
                        <input name="bucketLength" th:field="*{bucketLength}" class="form-control" onclick="selectBucket()" readonly="readonly" id="length"  type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">箱宽度：</label>
                    <div class="col-sm-8">
                        <input name="bucketWidth" th:field="*{bucketWidth}" class="form-control" type="text" readonly="readonly" id="width">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">箱高度：</label>
                    <div class="col-sm-8">
                        <input name="bucketHeigth" th:field="*{bucketHeigth}" class="form-control" type="text" readonly="readonly" id="heigth">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label ">单位：</label>
                    <div class="col-sm-8">
                        <select name="bucketUnitname" class="form-control"  required>
                            <option th:each="name : ${uniteNames}" th:text="${name}" th:value="${name}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">是否需要包皮：</label>
                    <div class="col-sm-8">
                        <select name="applyHusk" class="form-control" th:with="type=${@dict.getType('order_husk_apply')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{applyHusk}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">包皮颜色：</label>
                    <div class="col-sm-8">
                        <input name="huskColor" th:field="*{huskColor}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">状态：</label>
                    <div class="col-sm-8">
                        <input name="status" th:field="*{status}" class="form-control" type="text" readonly="readonly">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea name="common" class="form-control">[[*{common}]]</textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "process/order";
        $("#form-order-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-order-edit').serialize());
            }
        }

        $("input[name='deadtime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function selectClient() {
            var url = ctx + "main/client";
            var options = {
                title: '选择客户',
                height: "500",
                width: "800",
                url: url,
                callBack: doSupplylSubmit
            };
            $.modal.openOptions(options);
        }

        function doSupplylSubmit(index, layero) {
            var rows = layero.find("iframe")[0].contentWindow.getClientSelections();
            if(rows <= 0){
                alert("请至少选择一条数据")
            }
            else {
                $("#clientName").val(rows[0].name)
                $("#clientPhone").val(rows[0].phone)
                $.modal.close(index)
            }
        }


        function selectProduct() {
            var url = ctx + "wms/productstock";
            var options = {
                title: '选择产品',
                height: "500",
                width: "800",
                url: url,
                callBack: doProductlSubmit
            };
            $.modal.openOptions(options);
        }

        function doProductlSubmit(index, layero) {
            var rows = layero.find("iframe")[0].contentWindow.getProductSelections();
            if(rows <= 0){
                alert("请至少选择一条数据")
            }
            else {
                $("#productName").val(rows[0].name)
                $("#productModel").val(rows[0].model)
                $("#productId").val(rows[0].productId)
                $.modal.close(index)
            }
        }

        function selectBucket() {
            var url = ctx + "process/bucket";
            var options = {
                title: '选择箱型',
                height: "500",
                width: "800",
                url: url,
                callBack: doBucketlSubmit
            };
            $.modal.openOptions(options);
        }

        function doBucketlSubmit(index, layero) {
            var rows = layero.find("iframe")[0].contentWindow.getBucketSelections();
            if(rows <= 0){
                alert("请至少选择一条数据")
            }
            else {
                $("#length").val(rows[0].length)
                $("#width").val(rows[0].width)
                $("#heigth").val(rows[0].high)
                $.modal.close(index)
            }
        }

        function computedMoney() {
            var signal_price = $("#signal_price").val()
            var num = $("#num").val()

            $("#totalPrice").val(signal_price*num)
        }

    </script>
</body>
</html>